<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>Hello MUI</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">

		<link rel="stylesheet" href="css/mui.min.css">
		<linc rel="stylesheet" href="css/specific.css">
		<style type="text/css">
			.mui-content>.mui-table-view:first-child {
				margin-top: -1px;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<h1 id="title" class="mui-title"></h1>
		</header>
		<!--下拉刷新容器-->
		<div id="pullrefresh" class="mui-content">
			<!--数据列表-->
			<ul class="mui-table-view mui-table-view-chevron"></ul>
		</div>
		<script src="js/mui.min.js" type="text/javascript" charset="utf-8"></script>
		<script>

			mui.init({
				pullRefresh: {
					container: '#pullrefresh',
					down: {
						style:'circle',
						callback: pulldownRefresh
					},
					up: {
						auto:true,
						contentrefresh: '正在加载...',
						callback: pullupRefresh
					}
				}
			});
			var currentClass;
			mui.plusReady(function(){
				var self = plus.webview.currentWebview();
				currentClass = self.className;
//				console.log(currentClass);
				document.getElementById("title").innerHTML = currentClass;
			})
			
			var count = 0;
			function pullupRefresh() {
				setTimeout(function() {
					mui('#pullrefresh').pullRefresh().endPullup((++count > 2)); //参数为true代表没有更多数据了。
					var table = document.body.querySelector('.mui-table-view');
					var cells = document.body.querySelectorAll('.mui-table-view-cell');
					var newCount = cells.length>0?5:20;//首次加载20条，满屏
					for (var i = cells.length, len = i + newCount; i < len; i++) {
						var li = document.createElement('li');
						li.className = 'mui-table-view-cell cl_imgRow';
						li.align="center";
						li.float="left";
						li.innerHTML = buildRow();
						li.addEventListener('tap',function(e){
							showImg(2);
							});
//						li.innerHTML = '<a class="mui-navigate-right">Item ' + (i + 1) + '</a>';
						table.appendChild(li);
					}
				}, 1500);
			}

			function addData() {
				var table = document.body.querySelector('.mui-table-view');
				var cells = document.body.querySelectorAll('.mui-table-view-cell');
				for(var i = cells.length, len = i + 5; i < len; i++) {
					var li = document.createElement('li');
					li.className = 'mui-table-view-cell cl_imgRow';
					li.align = "center";
					li.float="left";
//					li.innerHTML = '<a class="mui-navigate-right">Item ' + (i + 1) + '</a>';
					li.innerHTML = buildRow();
//					console.log("addDate:"+li.innerHTML);
					li.addEventListener('tap',function(e){
						showImg(2);
					});
					//下拉刷新，新纪录插到最前面；
					table.insertBefore(li, table.firstChild);
				}
			}
			
			function buildRow(){
				return addImg("cardImg/2.jpg");
			}
			
			function addImg(src){
				var src =  '<img class="mImg" src="'+src+'" width="160px" height="90px" style="margin=10px" />'
				return src;
			}
			/**
			 * 下拉刷新具体业务实现
			 */
			function pulldownRefresh() {
				setTimeout(function() {
					addData();
					mui('#pullrefresh').pullRefresh().endPulldown();
					mui.toast("为你推荐了5篇文章");
				}, 1500);
			}

			function showImg(name){		//	name 参数为图片实际的编号（如果不是编号的名字在上下一张会报错）
				console.log('单击具体图片');
				mui.openWindow({
					url:"/imageViewer.html",
			    id:'imageViewer',
			    styles:{
			      top:'0',//新页面顶部位置
			      bottom:'0',//新页面底部位置
			      width:'100%',//新页面宽度，默认为100%
			      height:'100%',//新页面高度，默认为100%
			    },
			    extras:{
			   		imgUrl : ('img'),
			   		prefix : '',
			   		suffix : '.jpg',
			   		currentIndex : name,
			   		begin : 1,
			   		end : 10,
			   	  
			    },
			    createNew:false,//是否重复创建同样id的webview，默认为false:不重复创建，直接显示
			    show:{
			      autoShow:true,//页面loaded事件发生后自动显示，默认为true
//			      aniShow:animationType,//页面显示动画，默认为”slide-in-right“；
//			      duration:animationTime//页面动画持续时间，Android平台默认100毫秒，iOS平台默认200毫秒；
			    },
			    waiting:{
			      autoShow:true,//自动显示等待框，默认为true
			      title:'查看图片',//等待对话框上显示的提示内容
			      options:{
//			        width:waiting-dialog-widht,//等待框背景区域宽度，默认根据内容自动计算合适宽度
//			        height:waiting-dialog-height,//等待框背景区域高度，默认根据内容自动计算合适高度
			      }
			    }
				});
			}

		</script>
	</body>
	<!--<img style="ma" />-->
</html>